/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.yunhoo.asset.db.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 *
 * @author Administrator
 */
public class JdbcOperation {
    public static Connection dbConn(){
        Connection conn = null;
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=cea","sa","cw");     
        }
        catch(Exception e){
            System.out.println(e.getLocalizedMessage());
        }
        return conn;
    }

    public void importFromRemoteServer(){
        try{
            Connection conn = dbConn();
            Statement stmt = conn.createStatement();
            //conn.setAutoCommit(false);
            String sqlStr = "insert into sala_wadata " +
                            " select * from " +
                            " openrowset( 'SQLOLEDB','192.168.0.103';'sa';'cw',' + " +
                            " select * from ufdata_005_2011.dbo.wa_gzdata " +
                            " where imonth = 7') ";
            String cc = "insert into sala_wadata " +
                        " select * from " +
                        " opendatasource('SQLOLEDB','Data Source=yunhoo;User ID=sa;Password=cw').ufdata_005_2011.dbo.wa_gzdata where imonth = 7";
            stmt.executeUpdate(cc);
//            ResultSet rst= stmt.executeQuery(cc);
//            while(rst.next())
//                System.out.println(rst.getString(1));

           // conn.commit();
        }
        catch(Exception e){
            System.out.println(e.getLocalizedMessage());
        }
    }

    public static void main(String[] args){
        JdbcOperation oper = new JdbcOperation();
        oper.importFromRemoteServer();
   
    }
}
